package com.derbysoft.lowcostadapter.commons.model;

import com.derbysoft.lowcostadapter.commons.redis.service.RedisSerializable;
import com.derbysoft.lowcostadapter.commons.redis.utils.RedisValueBuilder;
import com.derbysoft.lowcostadapter.commons.utils.CheckUtils;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;

@Entity
public class Hotel implements RedisSerializable {

    public static final String PASSPORT_PREFIX = "H_PR:";

    public static final String ID_PREFIX = "H_ID:";

    @Id
    private int propertyID;

    private String passport;

    private String name;

    @Enumerated(EnumType.STRING)
    private Status status;

    public String getPassport() {
        return passport;
    }

    public void setPassport(String passport) {
        this.passport = passport;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPropertyID() {
        return propertyID;
    }

    public void setPropertyID(int propertyID) {
        this.propertyID = propertyID;
    }

    public void setPropertyID(String propertyID) {
        if (CheckUtils.checkNumber(propertyID)) {
            this.propertyID = Integer.parseInt(propertyID);
        }
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    @Override
    public String toKey() {
        throw new UnsupportedOperationException("Hotel unsupported toKey()");
    }

    @Override
    public String toFiled() {
        throw new UnsupportedOperationException("Hotel unsupported toFiled()");
    }

    @Override
    public Long expireTime() {
        return null;
    }

    @Override
    public String value() {
        RedisValueBuilder redisValueBuilder = new RedisValueBuilder();
        redisValueBuilder.append(getPropertyID());
        redisValueBuilder.append(getPassport());
        redisValueBuilder.append(getName());
        redisValueBuilder.append(getStatus());
        return redisValueBuilder.toString();
    }
}
